<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="model.Reservation" %>
<%@ page import="model.Booking" %>
<%@ page import="model.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="dao.intf.RoomTypeDao" %>
<%@ page import="dao.impl.RoomTypeDaoImpl" %>
<%@ page import="dao.intf.BookingDao" %>
<%@ page import="dao.impl.BookingDaoImpl" %>
<%@ page import="model.RoomType" %>
<%@ page import="dao.intf.UserDao" %>
<%@ page import="dao.impl.UserDaoImpl" %>

<%@page import="model.RoomType"%>
<%@page import="java.util.List" %>
<%@page import="java.util.*" %>


<!DOCTYPE HTML>
<html>
<head>
    <title>Hotel Arbour : View Detail</title>
    <script src="js/jquery-1.9.1.js" language="javascript"></script>
	<script src="js/jquery-ui-1.10.2.custom.js" language="javascript"></script>
	<script type="text/javascript" src="js/post_watermarkinput.js"></script>
	<link rel="stylesheet" href="CSS/ui-lightness/jquery-ui-1.10.2.custom.css" type="text/css">
	<link href="CSS/vasplus_programming_blog_CSS.css" rel="stylesheet" type="text/css"> 
	
<script>
$(function() {
	$( "#accordion" ).accordion();	
	
	var date = new Date();
	var currentYear = date.getFullYear();
	var currentMonth = date.getMonth();
	var currentDate = date.getDate();
	var currentDate2 = date.getDate() + 1;
	
	$("#checkindate").datepicker({
		onSelect: function (date) {
			if ($("#checkindate").val() != '' && $("#checkoutdate").val() != ''){
				var start = $('#checkindate').datepicker('getDate');
			    var end = $('#checkoutdate').datepicker('getDate');
			    var diff = (end - start)/1000/60/60/24;
				$("#night").val(diff);
				//alert(diff);
			}            
        },
		dateFormat: "yy-mm-dd",
		minDate:new Date(currentYear, currentMonth, currentDate)
	});
	
	$("#checkoutdate").datepicker({
		onSelect: function (date) {
			if ($("#checkindate").val() != '' && $("#checkoutdate").val() != ''){
				var start = $('#checkindate').datepicker('getDate');
			    var end = $('#checkoutdate').datepicker('getDate');
			    var diff = (end - start)/1000/60/60/24;
				$("#night").val(diff);
				//alert(diff);
			}
            
        },
		dateFormat: "yy-mm-dd",
		minDate:new Date(currentYear, currentMonth, currentDate2)		
	});
	
});	

	
</script>
<script language="javascript">
	function toggleDiv() {
		alert('toggleDiv');
		document.getElementById('viewDetail').style.display = "";
		document.getElementById('reserveDetail').style.display = "none";
	}
	
	function regSubmit() {
		alert ('Registeration Successful !');
		document.getElementById('content').style.display = "";
		document.getElementById('register').style.display = "none";
	}
	
	function displayRates() {
		document.getElementById('content').style.display = "none";
		document.getElementById('register').style.display = "none";
		document.getElementById('rateList').style.display = "";
	}
	function createObject() {
		var request_type;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			request_type = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			request_type = new XMLHttpRequest();
		}
		return request_type;
	}

	var http = createObject();

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
	var nocache = 0;
	function login() {
		
		document.getElementById('login_loading').style.display = "" ;		
		var email = encodeURI(document.getElementById('emailLogin').value);
		var psw = encodeURI(document.getElementById('pswLogin').value);
	// Set te random number to add to URL request
		nocache = Math.random();
	// Pass the login variables like URL variable
		http.open('get', 'login.html?email='+email+'&psw='+psw+'&nocache = '+nocache);
		http.onreadystatechange = loginReply;
		http.send(null);
	}
	
	function loginReply() {
		document.getElementById('login_loading').style.display = "none" ;
		if(http.readyState == 4){ 
			var response = http.responseText;
			if(response == 0){
	// if login fails
				document.getElementById('login_response').innerHTML = 'Login failed! Verify user and password';
	// else if login is ok show a message: "Welcome + the user name".
			} else {
				document.getElementById('login_response').innerHTML = 'Welcome'+response;
			}
		}
	}
	
			
</script>

<script>
$(document).ready(function() { 
	
	//if ($('#checkindate').onSelect == true) alert ('checkin');
	
    $('#btnRates').click(function(event) { 
    	var msg = '';
    	if ($('#checkindate').val() == '') 
			msg = msg + 'Please select Check In date.\n';
    	if ($('#checkoutdate').val() == '') 
			msg = msg  + 'Please select Check Out date.\n';	
    	if ($('#adult').val() == '' )
			msg = msg  + 'Please enter number of Adult(s).\n';
		if ($('#children').val() == '' )
			msg = msg  + 'Please enter number of Children.\n';
		if (parseInt($('#night').val()) < 1 )
			msg = msg  + 'Checkin date must be earlier than Checkout date.\n';
		
		if (msg != '' ) alert (msg);
		else{
			$('#action').val('checkrates');
			$('#checkrates').val("1");
			$('#frmIndex').submit();
	    	  
	        
		}//end else
    	
    });
});
$(document).ready(function(){	
	
	//$('#availability').attr('style' , 'display:none');
	$('#rooms').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}
	}); 
	$('#adult').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}
	});
	$('#children').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}		
	});
	$('#night').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}
	});	
});


	
</script>


</head>
<body style="font-family:Calibri;">
<form id="frmindex" name="frmindex" method="POST" action="/ReservationSystem/ViewDetailServlet">	
	<div id="body" style="width:900px ;margin:0 auto; padding:0 0 0 0 auto;">
	
	<!-- Header-->		
		<input type="hidden" value="" name="checkrates" id="checkrates">
		<input type="hidden" value="" name="action" id="action" value="">
		<table width="100%" border="0px" cellpadding="0">
		<tr>
			<td><img src="images/logo.jpg" /></td>
			
			<td colspan="2">
				<p align="right" style="font-weight:bold;">			
					<a href="index.jsp" style="text-decoration:none;"><font style="color:#7E354D">Home&nbsp;&nbsp;|&nbsp;&nbsp;</font></a>
					<a href="index.jsp" style="text-decoration:none;"><font style="color:#7E354D">Promotion&nbsp;&nbsp;|&nbsp;&nbsp;</font></a>
					<a href="index.jsp" style="text-decoration:none;"><font style="color:#7E354D">Rooms&nbsp;&nbsp;&nbsp;</font></a>						
				</p> 
				<p align="right" style="font-weight:bold;">
					<div id="login_response"></div>	
				</p>					
				
			</td>
		</tr>
        <tr>
            <td style="width:65%;vertical-align:top;">
				<video width="600" height="260" controls>
				<source src="movie.mp4" type="images/Sample.mp4"></source></video>
				
            </td>
			
            <td style="width:35%;vertical-align:top;"> 
				<table border="0px" width="100%">
					<tr>
					    <td>
					        <div id="accordion">	
                                 <h1 style="border:1px solid #7E354D;"><font style="color:#7E354D">Reservation</font></h1>
					                <div>
					                    <table>
					                    <%
									   		
										%>
											<tr>
												<td>Check-In:</td>
												<td><input type="text" id="checkindate" name="checkindate" readonly="readonly" value=''/></td>
											</tr>
											<tr>
												<td>Check-Out:</td>
												<td><input type="text" id="checkoutdate" name="checkoutdate" value=''/></td></tr>
											<tr>
												<td>Room Type:</td>												
											    <td><select name="roomtype" id="roomtype">
											    	<option value='All'>--- All Room ---</option>
											    	<%
														
												    	List<RoomType> roomTypeList = new ArrayList<RoomType>();
												    	RoomTypeDaoImpl roomTypeDaoObj = new dao.impl.RoomTypeDaoImpl();
												    	roomTypeList = roomTypeDaoObj.getRoomTypeList();
												    	
												    	for (int i = 0 ; i < roomTypeList.size() ; i ++){	
															out.println("<option value='"+roomTypeList.get(i).getId()+"'>" + roomTypeList.get(i).getName() + "</option>");																
														}	
													%>                                                   
                                                </select>&nbsp;
                                                 
                                                </td>
											</tr>																						
											<tr>
												<td colspan="2" align="center">
													Rooms:&nbsp;&nbsp;Adult:&nbsp;&nbsp;Children:&nbsp;&nbsp;Nights:
													<br><input type="text" id="rooms" name="rooms" size="2" maxlength="3" value=''/>&nbsp;
													&nbsp;&nbsp;<input type="text" id="adult" name="adult" size="3" maxlength="3" value=''/>&nbsp;
													<input type="text" id="children" name="children" size="3" maxlength="1" value=''/> 
													&nbsp;&nbsp;<input type="text" id="night" name="night" size="2" maxlength="3" value=''/>&nbsp;
														
												</td>
											</tr>											
											
											<tr>
												<td colspan="2" align="center">
													<input type="button" id="btnRates" value="Check Rates"/>&nbsp;
													<a href="search.jsp" style="text-decoration:none;"><font style="color:#7E354D">View&nbsp;|&nbsp;</font></a>
													<a href="search.jsp" style="text-decoration:none;"><font style="color:#7E354D">Modify&nbsp;|&nbsp;</font></a> 
													<a href="search.jsp" style="text-decoration:none;"><font style="color:#7E354D">Cancel&nbsp;</font></a>
												</td>
											</tr>
										</table>
                                    </div> 
                                     <h1 style="border:1px solid #7E354D;"><font style="color:#7E354D">Corporate Login</font></h1>
					                <div>
										<table>
											<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
											
											<tr><td>Login ID:</td><td><input type="text" id="emailLogin" name="emailLogin" size="10"/></td></tr>
											<tr><td>Password:</td><td><input type="text" id="pswLogin" name="pswLogin" size="10"/></td></tr>
											<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
											<tr><td>&nbsp;</td><td><input type="button" id="btnLogin" name="btnLogin" value="Log In" onclick="login();"/>&nbsp;
																	<input type="button" id="signup" name="signup" value="Sign Up" onclick="toggleDiv();"/></td></tr>
										</table>
                                    </div>                                 
					        </div>
					    </td>
					</tr>					
				</table>
			</td>
        </tr>
    </table>

    <!-- Header-->	
	<%
	
	
	String bookingId = "";
	String bookingEmail = "";

	bookingId = request.getParameter("bookingid");
	bookingEmail = request.getParameter("bookingemail");
	User userTemp = new User();
	UserDao userDao = new UserDaoImpl();
	BookingDao bookingDao=new BookingDaoImpl();
	Booking booking=new Booking();
	Reservation reservation=new Reservation();
	if (bookingId != "") {
		
		booking=bookingDao.getBookingById(bookingId);		
		userTemp = userDao.getUserById(booking.getUserId());
		//userTemp = userDao.getUserByEmail("bookingEmail");
		out.println(" room type : " + booking.getRoomType());
		
		RoomType roomType=new RoomType();
		RoomTypeDao roomTypeDao=new RoomTypeDaoImpl();
		roomType=roomTypeDao.getRoomTypeById(booking.getRoomType());
		reservation.setBooking(booking);
		reservation.setUser(userTemp);
		session.setAttribute("reservation", reservation);
		
	}
	String status="";
	if (request.getAttribute("status") != null )status=request.getAttribute("status").toString();

	 
	%>
 <%if (status.equals("")) {%>
	
   <div id="viewdetail" style="font-size:15px;">
   <table width="70%" border="0px" align="center" style="font-size:15px;-khtml-border-radius: 20px;-moz-border-radius: 20px;-ms-border-radius: 20px;-o-border-radius: 20px;-webkit-border-radius: 20px;border-radius: 20px;
				border: solid 1px gray;" cellpadding="5px">	
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td>Booking number : </td><td><%=booking.getId()%></td>
			</tr>
			<tr>
				<td>Room Type : </td><td><%=booking.getRoomTypeName() %></td>
			</tr>
				<td>Arrival/Departure : </td><td><%=new SimpleDateFormat("dd/MM/yyyy").format(booking.getStart()) %> - <%=new SimpleDateFormat("dd/MM/yyyy").format(booking.getEnd()) %></td>
			</tr>
			</tr>
				<td>Standard Check-In Time : </td><td>15:00</td>
			</tr>
			</tr>
				<td>Standard Check-Out Time : </td><td>15:00</td>
			</tr>
			<tr>
				<td>Number of Nights : </td><td><%=booking.getDuration() %></td>
			</tr>
			<tr>
				<td>Adults / Children : </td><td><%=booking.getAdults() %> / <%=booking.getChildren() %></td>
			</tr>
			<tr>
				<td>Number of Units : </td><td><%=booking.getNumberofUnits() %></td>
			</tr>
			
			<tr><td><b>Guest Information</b></td></tr>
			<tr>
				<td>Title:<br>Ms.
				<td>First Name:<br><%=userTemp.getFirstName() %></td>
				<td>Last Name:<br><%=userTemp.getLastName() %></td>
			</tr>
			<tr>
				<td>Email:<br><%=userTemp.getEmail() %></td>
				<td colspan="2">Contact No.:<br><%=userTemp.getContactNo() %></td>
			</tr>
			<tr>
				<td colspan="3">Address:<br><%=userTemp.getAddress() %></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="3" align="center">
				<input type="submit" id="cancel" name="cancel" value="cancel"/>
				<input type="submit" id="edit" name="edit" value="Edit"/></td>
			</tr>
			
		</table>
		
	</div>
	<%}else if (status.equals("ok")){ %>
	 <table width="70%" border="0px" align="center" style="font-size:15px;-khtml-border-radius: 20px;-moz-border-radius: 20px;-ms-border-radius: 20px;-o-border-radius: 20px;-webkit-border-radius: 20px;border-radius: 20px;
				border: solid 1px gray;" cellpadding="5px">	
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2">Your reservation has been Cancelled</td>
			</tr>
			</table>
	<%}else if (status.equals("fail")){ %>
		 <table width="70%" border="0px" align="center" style="font-size:15px;-khtml-border-radius: 20px;-moz-border-radius: 20px;-ms-border-radius: 20px;-o-border-radius: 20px;-webkit-border-radius: 20px;border-radius: 20px;
				border: solid 1px gray;" cellpadding="5px">	
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2">Cancellation Error </td>
			</tr>
			</table>
	<%} %>
	
   </div>
 
</form>
</body>
</html>
    